/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "company_sector")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CompanySector.findAll", query = "SELECT c FROM CompanySector c"),
    @NamedQuery(name = "CompanySector.findByIdCompanySector", query = "SELECT c FROM CompanySector c WHERE c.idCompanySector = :idCompanySector")})
public class CompanySector implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_COMPANY_SECTOR")
    private Integer idCompanySector;
    @JoinColumn(name = "ID_SECTOR", referencedColumnName = "ID_SECTOR")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Sector idSector;
    @JoinColumn(name = "ID_COMPANY", referencedColumnName = "ID_COMPANY")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Company idCompany;

    public CompanySector() {
    }

    public CompanySector(Integer idCompanySector) {
        this.idCompanySector = idCompanySector;
    }

    public Integer getIdCompanySector() {
        return idCompanySector;
    }

    public void setIdCompanySector(Integer idCompanySector) {
        this.idCompanySector = idCompanySector;
    }

    public Sector getIdSector() {
        return idSector;
    }

    public void setIdSector(Sector idSector) {
        this.idSector = idSector;
    }

    public Company getIdCompany() {
        return idCompany;
    }

    public void setIdCompany(Company idCompany) {
        this.idCompany = idCompany;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCompanySector != null ? idCompanySector.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        boolean res=false;
        if (object instanceof CompanySector) {
            CompanySector other=(CompanySector)object;
//            if(this.getIdCompanySector()!=null && other.getIdCompanySector()!=null){
//                res=this.getIdCompanySector().equals(other.getIdCompanySector());
//            }
//            else{
                res=this.getIdSector().getIdSector().equals(other.getIdSector().getIdSector()) && this.getIdCompany().getIdCompany().equals(other.getIdCompany().getIdCompany());
//            }
        }
        return res;
    }

    @Override
    public String toString() {
        return "entities.CompanySector[ idCompanySector=" + idCompanySector + " ]";
    }
    
}
